---------------------------------------------------------------------------------
  -- Design Name : Inc/Dec Stack Pointer Register
  -- File Name   : ExMemMemory.vhd
  -- Function    : Simple synchronous RAM memory
  -- Authors     : Mirko Francuski  2006/0225
  --               Milos Mihajlovic 2006/0039
  -- School      : University of Belgrade
  --               School for Electrical Engineering
  --               Department for Computer Engineering and Information Theory
  -- Subject     : VLSI Computer Systems
---------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
use work.UserPkg.all;
use work.TBPkg.all;

entity ExMemMemory is
    port (
      clk     : in  std_logic;
      we      : in  std_logic;
      addr    : in  stackAddr;
      dataIn  : in  word32;      
      dataOut : out word32 := (others => '0')
    );
end ExMemMemory;

architecture behavioral of ExMemMemory is
  type t_mem is array(0 to STACK_SIZE - 1) of word32; -- =1kB
  signal RAM : t_mem := (others => "00000000000000000000000000000000");
    
begin

  process(clk)
  begin    
    if rising_edge(clk) then
      --if addr /= "Z" then
        dataOut <= RAM(to_integer(unsigned('0' & addr)));
        if (we = '1') then
          RAM(to_integer(unsigned('0' & addr))) <= dataIn;
        end if;
      --end if;
    end if;
  end process;

end architecture behavioral;
